﻿@model IEnumerable<MVCTutorial.Core.Model.User>

@{
    ViewBag.Title = "Usuários";
}

<h2>Usuários</h2>

<p>
    @Html.ActionLink("Novo Usuário", "Create")
</p>

<div>
	<input type="text" id="nameLike" /> 
	<input type="button" id="btnSearch" value="buscar" />
	<br />
	<br />
</div>

<div id="users">
	@{ Html.RenderPartial("Partial/UserList", Model); }
</div>

<script	type="text/javascript">
	$(function(){
		
		var searchUsers = function()
		{
			$.ajax({
				url: "@Url.Content("~/User/Search")",
				data: "nameLike=" + $("#nameLike").val(),
				type: "post",
				success: function(data)
				{
					$("#users").html(data);
				}
			});
		};


		$("#btnSearch").click(function(){
			searchUsers();
		});

		// exclusão via tabela em Partial/UserList
		$(".del-user").live("click", function () 
		{
			if (confirm("Confirma exclsuão?")) 
			{
				id = $(this).attr("target");

				$.ajax({
					url: "@Url.Content("~/User/Delete/")" + id,
					type: "get",
					success: function()
					{
						searchUsers();
					}
				});
			}
		});

	});
</script>